﻿/// @creator: Slipp Douglas Thompson
/// @license: Public Domain per The Unlicense.  See <http://unlicense.org/>.
/// @purpose: A UnityEngine.UI.Graphic subclass that provides only raycast targeting, skipping all drawing.
/// @why: Because this functionality should be built-into Unity.
/// @usage: Add a `NonDrawingGraphic` component to the GameObject you want clickable, but without its own image/graphics.
/// @intended project path: Assets/Plugins/UnityEngine UI Extensions/NonDrawingGraphic.cs
/// @interwebsouce: https://gist.github.com/capnslipp/349c18283f2fea316369

using UnityEngine;
using UnityEngine.UI;

/// Unity UI“Graphic”类的具体子类，它跳过了绘制操作。
/// 可用于提供射线投射目标，而无需实际绘制任何内容。
[AddComponentMenu("Layout/Extensions/NonDrawingGraphic"), RequireComponent(typeof(CanvasRenderer))]
public class NonDrawingGraphic : MaskableGraphic
{
    public override void SetMaterialDirty() { return; }
    public override void SetVerticesDirty() { return; }

    /// 可能没有必要，因为调用链“Rebuild()”->“UpdateGeometry()”->“DoMeshGeneration()”->“OnPopulateMesh()”不会发生；所以这里实际上只是作为一种故障保护。
    protected override void OnPopulateMesh(VertexHelper vh)
    {
        vh.Clear();
        return;
    }
}